<?php


   class SystemAction extends CommonAction{
   
      public function index(){
	    
		if(!empty($_POST)){
		
		  if($_POST['mohudu']>60){
		  
		    $this->error('模糊度不能大于60');
		  
		  }
		
		
		  $re=M('system')->where('id=1')->save($_POST);
		  
		  if($re!==false){
		    
			$this->success('修改配置成功');
		    exit();
		  }else{
		  
		    $this->error('修改失败');
		  
		  }
		
		}
		
	    $this->re=M('system')->where('id=1')->find();
	    $this->display();
	  
	  }
	  
	  
	  
	  public function beijing(){
	  
	  
	    $this->re=$this->page("beijingtu",10,'id desc');
	  
	    $this->display();
	  
	  }

	  public function ciku(){
	  
	  
	    $this->re=$this->page("ciku",10,'id desc');
	  
	    $this->display();
	  
	  }
	  
	  
	  public function add(){
	  
	     if($_POST){
		 
		 
		    $info=$this->upload('./images/'.date(Ymd)."/");
			
			if($info){
			
			  //dump($info);die;
			
			  $arr['img']="/images/".date(Ymd)."/".$info[0]['savename'];
			
			
			  $re=M('beijingtu')->add($arr);
			
			  if($re){
			  
			    $this->success('添加成功');exit();
			  
			  }else{
			  
			    $this->error('添加失败');
			  
			  
			  }
			
			
			}
			
			
		 
		 }
	  
	  
	     $this->display();
	  
	  }

	   public function addciku(){
	  
	     if($_POST){
		 
		 
			
			  
			
			  $arr['name']= $_POST['name'];
			
			
			  $re=M('ciku')->add($arr);
			
			  if($re){
			  
			    $this->success('添加成功');
			  
			  }else{
			  
			    $this->error('添加失败');
			  
			  
			  }
			
			
		
			
			
		 
		 }else{
	  
	  
	     $this->display();
	    }
	  
	  }
	  
	  
	  
	  public  function del(){
	  
	  
	    $this->ajaxReturn((M('beijingtu')->where('id="%s"',$_POST['id'])->delete())?1:2);
	  
	  
	  }

	  public  function delciku(){
	  
	  
	    $this->ajaxReturn((M('ciku')->where('id="%s"',$_POST['id'])->delete())?1:2);
	  
	  
	  }
	  
	  
	  public function kouliang(){
	  
	    if(!empty($_POST)){
		
		  $result=M('kouliang')->where('num="%s"',$_POST['num'])->find();
		  
		  if($result!=null){
		  
		  
		    $ajax=3;
		  
		  }else{
		
		
		
			  $re=M('kouliang')->add($_POST);
			
			  if($re){
				
				$ajax=1;
			  
			  }else{
			  
				$ajax=2;
			  
			  }
	     }	
		
		
		  $this->ajaxReturn($ajax);
		
		}
	  
	    $this->sys=M('system')->where('id=1')->find();
	    $this->re=M('kouliang')->order('id desc')->select();
	  
	     $this->display();
	  
	  }
	  
	  
	  
	  public function delkouliang(){
	  
	    $this->ajaxReturn((M('kouliang')->where('id="%s"',$_POST['id'])->delete())?1:2);
	  
	  
	  }
	  
	  
	  public function kouliangpeizhi(){
	  
	    $re=M('system')->where('id=1')->save($_POST);
		
		if($re!==false){
		
		  $this->success('设置成功');exit();
		
		}else{
		
		  $this->error('设置失败');
		
		}
		
	  
	  
	  }
	  
	  
	  public function xiangxi(){
	  
	   $where['kouliang']=array('eq','1');
	   $where['status']=array('eq','1');
	   $re=$this->page('buyer','10','id desc',$where);
	   
	   $i=-1;
	   foreach($re as $v){
	   
	     $i++;
		 
		 $pinku=M('pianku')->where('id="%s"',$v['pid'])->find();
	   
	     $re[$i]['title']=$pianku['title'];
	   
	   }
	   
	   
	   $this->re=$re;
	   $this->display();
	  
	  }
	  
   
   
   }